package util

import (
	"fmt"
	"math/rand"
	"os"
	"time"
)

// 随机生成指定长度的字符串
func RandomString(n int) string {
	var letters = []byte("asdfghjklqwertyuiopzxcvbnmASDFGHJKLQWERTYUIOPZXCVBNM")
	result := make([]byte, n)
	rand.Seed(time.Now().Unix())
	for i := range result {
		result[i] = letters[rand.Intn(len(letters))]
	}
	return string(result)
}

//PathExists 判断文件夹是否存在
func CreateDir(path string) error {
	_, err := os.Stat(path)
	if err == nil {
		return nil
	}
	if os.IsNotExist(err) {
		// 创建文件夹
		err := os.MkdirAll(path, os.ModePerm)
		if err != nil {
			//fmt.Printf("mkdir failed![%v]\n", err)
			return fmt.Errorf("mkdir faild")
		} else {
			return nil
		}
	}
	return err
}


